#include "CrumblingBlock.h"

#define DESTROY_TIMER 1.5f

#include "../SGD Wrappers/CSGD_Direct3D.h"
#include "../SGD Wrappers/CSGD_TextureManager.h"

#include "Camera.h"
#include "Physics.h"

CrumblingBlock::CrumblingBlock(void)
{
	//Init to clean value;
	DestroyTimer	= 0.0f;
	HasTriggered	= false;
	isActive		= true;
	objectID		= "Crumbling Block";
}


CrumblingBlock::~CrumblingBlock(void)
{
}

//HandleCollision
//-- Handles collision with all game objects that sets a timer to destroy itself.
void CrumblingBlock::HandleCollision(GameObject& other, CollisionInfo& info) 
{
	if( this->isActive && HasTriggered == false && ( other.GetObjectID() == "Player" || other.GetObjectID() == "MetalBox") )
	{
		DestroyTimer = DESTROY_TIMER;
		HasTriggered = true;
	}
}

//Update
//-- Called Once per frame and updates the current game object data
void CrumblingBlock::Update(float deltaTime) 
{

	if( HasTriggered == true && DestroyTimer > 0.0f )
	{
		//Update the timer if the object has been triggered. 
		DestroyTimer -= deltaTime;
	}
	else if(  HasTriggered == true && DestroyTimer <= 0.0f )
	{
		//If the timer has ticked down set the object to inActive.
		this->isActive = false;
		HasTriggered = false;
	}

}

//Render
//-- Used for all drawing of this game object
void CrumblingBlock::Render(void) const
{
	if( isActive == true )
		CSGD_TextureManager::GetInstance()->Draw(this->imageID, 
		(int)(this->positionX - Camera::GetInstance()->OffsetX()), 
		(int)(this->positionY - - Camera::GetInstance()->OffsetY()));
}